package com.hisense.hiioc.hismartplate.controller;

import com.alibaba.fastjson.JSONObject;
import com.hisense.hiioc.hismartplate.base.BaseController;
import com.hisense.hiioc.hismartplate.constants.URLConstant;
import com.hisense.hiioc.hismartplate.entity.response.BaseRes;
import com.hisense.hiioc.hismartplate.service.WeatherService;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther:liaohongbing@hisense.com
 * @date:2018/12/27 18:59
 * @des
 */

@RestController
@RequestMapping(URLConstant.GuideIndexURLMapping.BASE_URL)
public class GuideIndexController{

    @Autowired
    WeatherService weatherService;

    @GetMapping("/getWeather")
    public BaseRes<JSONObject> getWeatherData(){
        System.out.println("getWeather");
        BaseRes res = new BaseRes<JSONObject>();
        res.setErr_no(200);
        res.setErr_msg("success");

        JSONObject weatherData = weatherService.getWeather();
        JSONObject airData = weatherService.getAir();
        weatherData.put("aqi",airData.get("aqi"));
        weatherData.put("quality",airData.get("quality"));
        weatherData.put("pm25",airData.get("pm25"));

        res.setSST(weatherData);
        System.out.println(res);
        return res;
    }
}
